﻿using System;

namespace Budgetsch.WP7.Model.Live
{
    using Budgetsch.WP7.Model.DataService;
    using Budgetsch.WP7.ViewModel;
    using Budgetsch.WP7.WP7DataService;

    public class CommentDataService : ICommentDataService
    {
        private readonly CookieContainerViewModel _containerViewModel;

        public CommentDataService(CookieContainerViewModel containerViewModel)
        {
            _containerViewModel = containerViewModel;
        }

        #region Implementation of ICommentDataService

        public void SendIncomeComment(string message, int itemId, Action<IncomeComment, Exception> callback)
        {
            var client = new WP7DataServiceClient { CookieContainer = _containerViewModel.CookieContainer };
            client.AddIncomeCommentCompleted += (s, e) => callback(e.Result, e.Error);
            client.AddIncomeCommentAsync(message, itemId);
        }

        public void SendCostComment(string message, int itemId, Action<CostComment, Exception> callback)
        {
            var client = new WP7DataServiceClient { CookieContainer = _containerViewModel.CookieContainer };
            client.AddCostCommentCompleted += (s, e) => callback(e.Result, e.Error);
            client.AddCostCommentAsync(message, itemId);
        }

        public void SendSavingComment(string message, int itemId, Action<SavingComment, Exception> callback)
        {
            var client = new WP7DataServiceClient { CookieContainer = _containerViewModel.CookieContainer };
            client.AddSavingCommentCompleted += (s, e) => callback(e.Result, e.Error);
            client.AddSavingCommentAsync(message, itemId);
        }

        #endregion
    }
}
